package com.shujia.wyh.day03;

/*
    逻辑运算符：&&  ||
    问题1：&&与&有什么区别？
        ||与|有什么区别？
        从结果层面出发，从运算角度出发

    结论：
        1、无论是单或还是双或，或者是单与还是双与，从结果上来看，是一样的。
        2、单个与无论左边是false还是true，右边都会执行
        3、双与当左边是false的时候，右边就不会执行，结果为false；当左边是true的时候，右边会执行，结果是有false则false
        4、单个或无论左边是false还是true，右边都会执行
        5、双或当左边是true的时候，右边就不执行了，结果为true;当左边为false的时候，右边会执行，结果是有true则true
 */
public class OptLogicDemo2 {
    public static void main(String[] args) {
        int a = 3;
        int b = 4;
        int c = 5;

        System.out.println("=====& 逻辑与运算=================================");
        //& 逻辑与运算
        System.out.println((a > b) & (a > c)); // false
        System.out.println((a > b) & (a < c)); // false
        System.out.println((a < b) & (a < c)); // true
        System.out.println((a < b) & (a > c)); // false

        System.out.println("=====&& 短路与运算=================================");
        //&& 短路与运算
        System.out.println((a > b) && (a > c)); // false
        System.out.println((a > b) && (a < c)); // false
        System.out.println((a < b) && (a < c)); // true
        System.out.println((a < b) && (a > c)); // false

        System.out.println("=====| 逻辑或运算==================================");
        //| 逻辑或运算
        System.out.println((a > b) | (a > c)); // false
        System.out.println((a > b) | (a < c)); // true
        System.out.println((a < b) | (a < c)); // true
        System.out.println((a < b) | (a > c)); // true

        System.out.println("=====|| 逻辑或运算==================================");
        //|| 逻辑或运算
        System.out.println((a > b) || (a > c)); // false
        System.out.println((a > b) || (a < c)); // true
        System.out.println((a < b) || (a < c)); // true
        System.out.println((a < b) || (a > c)); // true

        System.out.println("****从运算角度出发理解1 &************************");
        int x = 3;
        int y = 4;
        boolean b1 = ((x++ == 3) & (y++ == 4));
        System.out.println("x:" + x);  // 4
        System.out.println("y:" + y);  // 5
        System.out.println("b1:" + b1); //true

        System.out.println("****从运算角度出发理解1 &&************************");
        x = 3;
        y = 4;
        boolean b2 = ((x++ == 3) && (y++ == 4));
        System.out.println("x:" + x); // 4
        System.out.println("y:" + y); // 5
        System.out.println("b2:" + b2); //true

        System.out.println("****从运算角度出发理解2 &************************");
        x = 3;
        y = 4;
        boolean b3 = ((x++ == 6) & (y++ == 4));
        System.out.println("x:" + x);  // 4
        System.out.println("y:" + y);  // 5
        System.out.println("b3:" + b3); // false

        System.out.println("****从运算角度出发理解2 &&************************");
        x = 3;
        y = 4;
        boolean b4 = ((x++ == 6) && (y++ == 4));
        System.out.println("x:" + x); // 4
        System.out.println("y:" + y); // 4
        System.out.println("b4:" + b4); // false

        System.out.println("===从运算角度出发理解1 |==================================");
        //|逻辑或运算
        x = 3;
        y = 4;
        boolean b5 = ((x++ == 3) | (y++ == 4));
        System.out.println("x:" + x); // 4
        System.out.println("y:" + y); // 5
        System.out.println("b5:" + b5); // true

        System.out.println("===从运算角度出发理解1 ||==================================");
        //||逻辑或运算
        x = 3;
        y = 4;
        boolean b6 = ((x++ == 3) || (y++ == 4));
        System.out.println("x:" + x); //
        System.out.println("y:" + y); //
        System.out.println("b6:" + b6); //

        System.out.println("===从运算角度出发理解2 |==================================");
        //|逻辑或运算
        x = 3;
        y = 4;
        boolean b7 = ((x++ == 6) | (y++ == 4));
        System.out.println("x:" + x); //
        System.out.println("y:" + y); //
        System.out.println("b7:" + b7); //

        System.out.println("===从运算角度出发理解2 ||==================================");
        //||逻辑或运算
        x = 3;
        y = 4;
        boolean b8 = ((x++ == 6) || (y++ == 4));
        System.out.println("x:" + x); //
        System.out.println("y:" + y); //
        System.out.println("b8:" + b8); //


    }
}
